package com.lc.user.express;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.user.express.app.AppContext;
import com.lc.user.express.baseactivity.DialogBaseActivity;
import com.lc.user.express.httpserver.GetCost;
import com.lc.user.express.my.MyStardandActivity;
import com.zcx.helper.http.AsyCallBack;

import static com.lc.user.express.R.id.account_fanhui;


/**
 * Created by Administrator on 2016/8/18.
 */
public class CostActivity extends DialogBaseActivity implements View.OnClickListener {

    private TextView phone;
    private LinearLayout fanhui;
    private TextView account;
    private TextView cartype;
    private TextView money;
    private TextView unit;
    private TextView price;
    private TextView jili;
    private TextView costs;
    private TextView couponprice;
    private TextView ordercosts;
    private TextView integral;
    private static String NUM;
    private TextView zhifu_pic;
    private TextView biaozhun;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cost);
        initviews();
        inflush();
    }

    @Override
    protected void onResume() {
        super.onResume();
        inflush();
    }

    private void inflush() {
        String orderid = getIntent().getStringExtra("orderid");
//        Toast.makeText(this,AppContext.myPreferences.getUid()+"___"+orderid+"___"+AppContext.myPreferences.getCityId(),Toast.LENGTH_LONG).show();


        new GetCost(AppContext.myPreferences.getUid(), orderid, AppContext.myPreferences.getCityId(), new AsyCallBack<GetCost.Info>() {

            @Override
            public void onStart(int type) throws Exception {
                super.onStart(type);
                showLoading();
            }

            @Override
            public void onSuccess(String toast, int type, GetCost.Info info) throws Exception {
                super.onSuccess(toast, type, info);
                account.setText(info.account);
                cartype.setText("(" + info.cartype + ")");


                Log.d("====================", info.payttime);

                if (info.payttime.equals("1")) {
                    money.setText("发货时付款:现金支付" + info.money + "元");
                } else {

                    money.setText("收货时付款:现金支付" + info.money + "元");
                }


                unit.setText("起步价(含" + info.unit + "公里)");
                price.setText(info.price + "元");
                jili.setText("超里程费(超出" + info.jili + "公里)");
                costs.setText(info.costs + "元");

                if (info.couponprice.equals("0")) {
                    couponprice.setText(info.couponprice + "元");
                } else {
                    couponprice.setText("-" + info.couponprice + "元");
                }

                Log.d(info.couponprice, "8888888888888888888");


                ordercosts.setText(info.ordercosts + "元");
                integral.setText(info.integral);
                zhifu_pic.setText(info.account + "元");
                NUM = info.webtel;
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
                dismissLoading();
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
                dismissLoading();
            }
        }).execute(this);
    }

    private void initviews() {
        account = (TextView) findViewById(R.id.account);
        cartype = (TextView) findViewById(R.id.cartype);
        money = (TextView) findViewById(R.id.money);
        unit = (TextView) findViewById(R.id.unit);
        price = (TextView) findViewById(R.id.price);
        jili = (TextView) findViewById(R.id.jili);
        costs = (TextView) findViewById(R.id.costs);
        couponprice = (TextView) findViewById(R.id.couponprice);
        ordercosts = (TextView) findViewById(R.id.ordercosts);
        integral = (TextView) findViewById(R.id.integral);
        zhifu_pic = (TextView) findViewById(R.id.zhifu_pic);
        biaozhun = (TextView) findViewById(R.id.biaozhun);

        phone = (TextView) findViewById(R.id.phone);
        fanhui = (LinearLayout) findViewById(account_fanhui);
        fanhui.setOnClickListener(this);
        phone.setOnClickListener(this);
        biaozhun.setOnClickListener(this);
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        ViewGroup viewGroup = (ViewGroup) getWindow().getDecorView();
        AppContext.ScaleScreenHelper.loadView(viewGroup);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.phone:
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + NUM));
                startActivity(intent);
                break;
            case account_fanhui:
                finish();
                break;
            case R.id.biaozhun:
                startActivity(new Intent(this, MyStardandActivity.class));
                break;
        }
    }
}
